App({
    onLaunch: function() {
       
        const updateManager = wx.getUpdateManager();
        updateManager.onCheckForUpdate(function (res) {
          // 请求完新版本信息的回调
          // console.log("8999999",res.hasUpdate);
          if (res.hasUpdate) {
            wx.showModal({
              title: '更新提示',
              content: '小程序有新的版本，是否下载并更新？',
              success: function (res) {
                if (res.confirm) {
                  // 新的版本已经下载好，调用 applyUpdate 应用新版本并重启
                  updateManager.onUpdateReady(function () {
                    let timer1 = setTimeout(() => {
                      updateManager.applyUpdate();
                      clearTimeout(timer1);
                    }, 2000);
                  });
    
                  updateManager.onUpdateFailed(function (res) {
                    console.log(res);
                    let timer2 = setTimeout(() => {
                      wx.showToast({
                        title: '更新失败，请下次再试',
                        icon: 'none',
                        duration: 2000
                      });
                      clearTimeout(timer2);
                    }, 2000);
                  });
                }
              }
            });
          }
        });
        var i = this;
        wx.getSystemInfo({
            success: function(t) {
                i.globalData.windowHeight = t.windowHeight, i.globalData.windowWidth = t.windowWidth;
            }
        });
    },
    globalData: {
        windowHeight: null,
        windowWidth: null
    }
});